-- @owner: opentestcase023
-- @date: 2022/02/24
-- @testpoint: 向src表中插入instead of 触发器，合理报错


--step1:建表;expect:成功
drop table if exists t_trigger_src_00065 cascade;
drop table if exists t_trigger_des_00065 cascade;
drop sequence if exists t_trigger_des_00065_seq1 cascade;
create table t_trigger_src_00065(id1 int, id2 int, id3 int) with (storage_type=ustore);
create table t_trigger_des_00065(id1 int, id2 int, id3 int) with (storage_type=ustore);
create sequence t_trigger_des_00065_seq1;

--step2:向src表中插入instead of 触发器;expect:合理报错
create or replace function insert_func()
returns trigger as $$
begin
delete from  t_trigger_des_00065 where id1=1;
return new;
end;
$$language plpgsql;
/
drop trigger if exists insert_trigger_1 on t_trigger_src_00065;
create trigger insert_trigger_1
instead of delete on t_trigger_src_00065
for each row
when(true)
execute procedure insert_func();
/

--step3:清理环境;expect:成功
drop trigger if exists insert_trigger_1 on t_trigger_src_00065;
drop table if exists t_trigger_src_00065 cascade;
drop table if exists t_trigger_des_00065 cascade;
drop sequence if exists t_trigger_des_00065_seq1 cascade;
drop function if exists insert_func;